(function (aopc) {
    aopc.addExpandPage(867, function (get) {
        const Bridge = get('UtilsCommon', 'Bridge');
        const PageCommon = get('UtilsCommon', 'PageCommon');
        const Common = get('UtilsCommon', 'Common');

        return {
            expandInit() {
                this.meetingAsrList = this.getProperty('MeetingAsrList');
            },
            getMeetingId() {
                return { pathQuery: `?$orderby=CreateDate desc&$filter=MeetingId eq @MeetingId &@MeetingId=${this.pageData.MeetingId}` };
            },
            downloadAsr({ property }) {
                if (!this.asrConfig) return;
                const { ConfId, MeetingTitle } = property.data;

                window.asrRecorder.authLogin((res) => {
                    if (res.token) {
                        PageCommon.showLoading("正在下载中，请稍后...");
                        Bridge.jsToNative('downloadAsr', { ConfId, MeetingTitle, Token: res.token, ApiServiceUrl: this.asrConfig.apiServiceUrl }, () => {
                            PageCommon.hideLoading();
                        });
                    }
                    else this.alert(res.message);
                }, this.asrConfig);
            },
            expandDataLoad({ data }) {
                if (data && data.MeetingId && data.AsrServiceUrl) {
                    this.asrConfig = {
                        apiServiceUrl: data.AsrServiceUrl,
                        username: data.AsrUserName,
                        password: data.AsrPassword
                    }
                }
            },
            pauseAsr({ property }) {
                this.pauseResumeAsr(property, '暂停', 'pause');
            },
            resumeAsr({ property }) {
                this.pauseResumeAsr(property, '恢复', 'resume');
            },
            pauseResumeAsr(property, name, fnName) {
                if (!this.asrConfig || property.isLoading) return;
                const { ConfId } = property.data;
                property.isLoading = true;

                window.asrRecorder.authLogin((res) => {
                    if (res.token) {
                        this.confirm(`确定要${name}该语音转写吗？`, () => {
                            window.asrRecorder[fnName](ConfId, () => {
                                const { serviceName, actionName } = property.serviceInterface;

                                const statusText = name === '暂停' ? 'paused' : 'started';
                                const entityData = { ConfId, StatusText: statusText };
                                const url = `MeetingAsr(${ConfId})`;

                                this.dispatchAction(serviceName, actionName, { url, MeetingAsr: entityData }).then(res => {
                                    property.isLoading = false;
                                    if (res.isSuccess !== false) {
                                        this.alertSuccess(`${name}成功！`, () => {
                                            this.refreshDataList();
                                            if (this.setHeaderStatusName) this.setHeaderStatusName(statusText);
                                            this.webSocket.send('setHeaderStatusName', { statusText });
                                        });
                                    }
                                });
                            });
                        });
                    }
                    else this.alert(res.message);
                }, this.asrConfig);
            },
            refreshDataList() {
                this.meetingAsrList.id = Common.createGuid();
                this.meetingAsrList.isCache = false;
                this.meetingAsrList.refreshOptions();
            }
        }
    });
})(window.aopc);